<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"  @submit.native.prevent @keyup.enter.native="handleQuery">
      <el-form-item label="表格名" prop="qKey">
        <el-input v-model="queryParams.qKey" placeholder="" clearable></el-input>
      </el-form-item>
      <el-form-item label="有效标记" prop="qIsUsed">
        <el-select v-model="queryParams.qIsUsed" clearable placeholder="">
          <el-option
            v-for="dict in dict.type.is_used"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <router-link class="link-type" :to="'/userConfig/uc-quo-table-add/add/0'" v-hasPermi="['userConfig:auditQuestionnaire:add']">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
          >新增</el-button>
        </router-link>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table ref="tables" v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" @sort-change="handleSortChange">
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="表格名" align="center" prop="name" width="500"/>
      <el-table-column label="有效标记" align="center" prop="isUsed">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.is_used" :value="scope.row.isUsed"/>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime"/>
      <el-table-column label="修改时间" align="center" prop="updateTime"/>
      <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width" width="150">
        <template slot-scope="scope">
          <router-link class="link-type" :to="'/userConfig/uc-quo-table-add/add/'+scope.row.id" v-hasPermi="['userConfig:ucQuoTable:edit']">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
            >修改</el-button>
          </router-link>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-school"
            @click="handleUsed(scope.row)"
            v-if="scope.row.isUsed!=1"
          >设置有效</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>

import {getToken} from "@/utils/auth";
export default {
  name: "UcQuoTable",
  dicts: ['is_used'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        qKey: "",
        qType: undefined,
        qIsUsed: undefined,
        pageNum: 1,
        pageSize: 10,
        isAsc: undefined,
        orderByColumn: undefined
      },
      // 表单参数
      form: {

      },
      // 表单校验
      rules: {

      },
      dialogTableVisible:false,
    };
  },
  created() {

  },
  activated() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      this.request({
        url: '/userConfig/ucQuoTable/list',
        method: 'get',
        params: this.queryParams
      }).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.isAsc = undefined;
      this.queryParams.orderByColumn = undefined;
      this.queryParams.pageNum = 1;
      this.$refs.tables.clearSort();
      this.getList();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 排序触发事件 */
    handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = this.getLowLineCase(column.prop);
      this.queryParams.isAsc = column.order;
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },


    handleUsed(row){
      this.request({
        url: '/userConfig/ucQuoTable/setIsUsed',
        method: 'post',
        data: row
      }).then(response => {
        this.$modal.msgSuccess("操作成功");
        this.getList();
      });
    },
  }
};
</script>

